class Stack:
    def __init__(self):
        self.items = []

    def push(self, item):
        self.items.append(item)

    def pop(self):
        if not self.is_empty():
            return self.items.pop()
        return None

    def is_empty(self):
        return len(self.items) == 0

    def peek(self):
        if not self.is_empty():
            return self.items[-1]
        return None

def max_nesting_depth(s):
    """栈计算括号的最大嵌套深度"""
    stack = Stack()
    max_depth = 0
    current_depth = 0
    for char in s:
        if char == '(':
            current_depth += 1
            stack.push(current_depth)
            if current_depth > max_depth:
                max_depth = current_depth
        elif char == ')':
            stack.pop()
            current_depth = stack.peek() if not stack.is_empty() else 0
    return max_depth

# 测试
if __name__ == "__main__":
    print(max_nesting_depth("(1+(2*3)+((8)/4))+1"))  # 输出: 3
    print(max_nesting_depth("(1)+((2))+(((3)))"))    # 输出: 3
    print(max_nesting_depth("1+2+3"))               # 输出: 0